module assoc_array;

int temp, imem[*] ;

initial
begin
   imem[2'd3] = 1;
   imem[16'hFFFF] = 2;
   imem[4'b1000] = 3;
   $display("Number of entries: %0d", imem.num);

   if( imem.first(temp) ) 
      $display("Index: %0d, Value: %d", temp, imem[temp] );
   else
      $display("Index %0d doesn't exist", temp);

   if( imem.next(temp) ) 
      $display("Index: %0d, Value: %d", temp, imem[temp] );
   else
      $display("Index %0d doesn't exist", temp);
   if( imem.next(temp) ) 
      $display("Index: %0d, Value: %d", temp, imem[temp] );
   else
      $display("Index %0d doesn't exist", temp);

//   //note the way the index is specified
//   //the index value at the definition was 4'b1000
//   //the index is accessed as 'd8 -> this would result in 32 bit index value
//   // and hence the next condition statement evaluates to FALSE
//   if( imem.exists('d8) ) 
//      $display( "imem['d8] has a valid data - imem.exists('d8)");
//   else
//      $display( "imem['d8] DOESN'T has a valid data - imem.exists('d8)");
//
//   //note the way the index is specified
//   //the index value at the definition was 4'b1000
//   // it is accesssed as 4'd8
//   if( imem.exists(4'd8) ) 
//      $display( "imem[4'd8] has a valid data - imem.exists(4'd8)");
//   else
//      $display( "imem[4'd8] DOESN'T has a valid data - imem.exists(4'd8)");
//
//   if( imem.exists(4'b1000) ) 
//      $display( "Index 8 has a valid data - imem.exists(4'b1000)");
//
//   // delete the value at the given index
//   imem.delete(16'd65535);
//
//   if( imem.exists(16'hFFFF) ) 
//      $display( "imem[16'hFFFF] has a valid data - imem.exists(16'hFFFF)");
//   else
//      $display( "imem[16'hFFFF] DOESN'T has a valid data - imem.exists(16'hFFFF)");
//
//   // temp is assigned the index value of the first element in the associative array
//   if( imem.first(temp) )
//      $display(" First entry is at index %0db ",temp);
//
//   if ( imem.next(temp) )
//      $display(" Next entry is at index %0h after the index 3",temp);
//
//   if ( imem.first(temp) )
//   do
//      $display("Index %0d, Value %0d", temp, imem[temp] );
//   while( imem.next(temp) );

end

endmodule
